﻿using System;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices.ComTypes;

using Elasticsearch.Synchronize.Domain.Events;
using Elasticsearch.Synchronize.Domain.Interface;

namespace Elasticsearch.Synchronize.DomainEventHandler.Handler
{
    public class ScanSynchronizeItemEventHandler : MediatR.NotificationHandler<ScanSynchronizeItemDomainEvent>
    {
        private readonly ISynchronizeItemRepository _syncItemRepository;

        public ScanSynchronizeItemEventHandler(ISynchronizeItemRepository syncItemRepository)
        {
            _syncItemRepository = syncItemRepository;
        }

        protected override void HandleCore(ScanSynchronizeItemDomainEvent notification)
        {
            Console.WriteLine("SynchronizeItem.Scan()");
            var items = _syncItemRepository.GetIdleAndEnabledItems();
            foreach (var item in items)
            {
                notification.SynchronizeItem.Merge(item).Pour();
            }
        }
    }
}